package com.skydonkey.config;

import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Queue;

@Configuration
public class RabbitConfig {

    public static final String CONVERSION_EXCHANGE_NAME = "video-conversion-exchange";
    public static final String CONVERSION_FLV_QUEUE_NAME = "video-conversion-mp4-to-flv-queue";
    public static final String CONVERSION_MP4_TO_FLV_ROUTING_KEY = "mp4-to-flv";


    public static final String VIDEO_SAMPLE_EXCHANGE_NAME = "video-sample-exchange";
    public static final String VIDEO_SAMPLE_QUEUE_NAME = "video-sample-queue";
    public static final String VIDEO_SAMPLE_ROUTING_KEY = "to-png";


    @Bean
    public Queue videoSampleQueue(){
        return new Queue(VIDEO_SAMPLE_QUEUE_NAME, true);
    }

    @Bean
    public DirectExchange videoSampleExchange(){
        return new DirectExchange(VIDEO_SAMPLE_EXCHANGE_NAME);
    }

    @Bean
    public Binding videoSampleBinding(Queue videoSampleQueue, DirectExchange videoSampleExchange){
        return BindingBuilder.bind(videoSampleQueue).to(videoSampleExchange).with(VIDEO_SAMPLE_ROUTING_KEY);
    }

    @Bean
    public Queue videoConversionMp4ToFlvQueue() {
        return new Queue(CONVERSION_FLV_QUEUE_NAME, true);
    }

    @Bean
    public DirectExchange videoConversionExchange() {
        return new DirectExchange(CONVERSION_EXCHANGE_NAME);
    }

    @Bean
    public Binding mp4ToFlvBinding(Queue videoConversionMp4ToFlvQueue, DirectExchange videoConversionExchange) {
        return BindingBuilder.bind(videoConversionMp4ToFlvQueue).to(videoConversionExchange).with(CONVERSION_MP4_TO_FLV_ROUTING_KEY);
    }
}
